package com.system.controller;

import com.system.pojo.EmployeeSalary;
import com.system.pojo.HistoryEmployeeSalary;
import com.system.service.EmployeeSalaryService;
import com.system.service.HistoryEmployeeSalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created by 陈文杰 on 2022/6/12 16:37
 */
@Controller
public class HistoryEmployeeSalaryController {

    @Autowired
    EmployeeSalaryService employeeSalaryService;

    @Autowired
    HistoryEmployeeSalaryService historyEmployeeSalaryService;
    @RequestMapping("/addForm")
    public String addForm(){
        List<EmployeeSalary> employeeSalaries = employeeSalaryService.queryEmployeeSalaryAll();
        historyEmployeeSalaryService.addHistoryEmployeeSalary();
        return "redirect:toFrom";
    }

    @RequestMapping("/toFrom")
    public ModelAndView toFrom() {
        ModelAndView modelAndView = new ModelAndView();
        List<HistoryEmployeeSalary> historyEmployeeSalaries = historyEmployeeSalaryService.queryHistoryEmployeeSalaryAll();
        modelAndView.addObject("historyEmployeeSalaries",historyEmployeeSalaries);
        modelAndView.setViewName("employeesSalaryForm");
        return modelAndView;
    }

    @RequestMapping("/queryDate")
    public ModelAndView queryDate(String date){
        ModelAndView modelAndView = new ModelAndView();
        List<HistoryEmployeeSalary> historyEmployeeSalaries = historyEmployeeSalaryService.queryHistoryEmployeeSalaryByDate(date);
        modelAndView.addObject("historyEmployeeSalaries",historyEmployeeSalaries);
        modelAndView.setViewName("employeesSalaryForm");
        return modelAndView;
    }
}
